<template>
	<view class="page-fade-in" :style="{opacity: pageOpc}">
		<template v-if="pageOpc">
			<view>
				<view class="launch-box flexWarpCenterColumn">
					<image src="/static/login/launchLogo.png" class="launchLogo"></image>
					<image src="/static/login/launchTips.png" class="launchTips"></image>
				</view>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageOpc:0,
				windowHeight: '',
				count: 1,
				timer: null,
				wxCode:"",
				openid:"",
			}
		},
		onLoad() {
			this.setTime();
			// this.wechatLogin();
		},
		onReady(){
			setTimeout(() => {
				this.pageOpc=1
			}, 100)
		},
		methods: {
			// 获取微信用户code
			wechatLogin() {
				let that = this
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						console.log(loginRes);
						that.wxCode=loginRes.code
						that.getOpenid();
					}
				});
			},
			getOpenid(){
				this.$request.post(this.$api.login, {
					js_code: this.wxCode
				}, {}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code==1) {
						uni.setStorageSync('token', data.userinfo.token)
						uni.reLaunch({
							url:'/pages/home/storeList'
						})
					}
				})
			},
			next(){
				clearInterval(this.timer);
				setTimeout(()=>{
					this.count=0
					uni.reLaunch({
						url:'/pages/home/storeList'
					})
					// uni.redirectTo({
					// 	url:'/pages/login/login?openid='+this.openid
					// })
				},500)
			},
			setTime(){
					let self=this
					// 倒计时
					var TIME_COUNT = 2; //倒计时60s
					if (!self.timer) {
						self.count = TIME_COUNT;
						self.timer = setInterval(() => {
							if (self.count > 0 && self.count <= TIME_COUNT) {
								self.count--;
								console.log(self.count)
							} else {
								clearInterval(self.timer);
								self.next()
								self.timer = null;
							}
						}, 1000)
					}
				
			}
		}
	}
</script>

<style lang="scss">
	.launch-box{
		height: 100vh;
		justify-content: center;
		background: #EEB94D;
		.launchLogo{
			width: 600upx;
			height: 425upx;
		}
		.launchTips{
			width: 400upx;
			height: 476upx;
			margin-top: 106upx;
		}
	}
</style>
